package com.carkeeper.userOrder.controller;

import com.carkeeper.common.utils.PageResult;
import com.carkeeper.common.utils.Result;
import com.carkeeper.common.utils.StatusCode;
import com.carkeeper.pojo.CarBill;
import com.carkeeper.userOrder.service.CarBillService;
import com.github.pagehelper.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zhangmingxin
 * @version 1.0
 * @date 2020/11/27 1:03
 */
@RestController
@CrossOrigin
@Api(tags = "车主账单接口api")//标签专门用来标注类的
@RequestMapping("/carBill")
public class CarBillController {

    @Autowired
    private CarBillService carBillService;


    //查询车主账单表 +多条件查询+分页查询
    @GetMapping("/findPage")
    @ApiOperation("条件查询+分页接口")//标注方法
    @ApiImplicitParams({//参数集合
            @ApiImplicitParam(name = "id",value = "主键",defaultValue = "290682")
    })
    public Result findPage(CarBill carBill, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize){
        Page<CarBill> orderPage=carBillService.findPage(carBill,pageNum,pageSize);
        PageResult pageResult = new PageResult(orderPage.getTotal(),orderPage.getResult());
        return new Result(true, StatusCode.OK,"查询订单成功",pageResult);
    }

    /**
     * 根据账单主键id查询
     * @param id
     * @return
     */
    @GetMapping("/findByOrderId/{id}")
    @ApiOperation("账单id查询接口")//标注方法
    @ApiImplicitParams({//参数集合
            @ApiImplicitParam(name = "id",value = "主键",defaultValue = "车主账单id")
    })
    public Result findByOrderId(@PathVariable("id") Long id){
        Map map = carBillService.findById(id);
        return new Result(true,StatusCode.OK,"查询账户详情成功",map);

    }
}
